package org.tea.inventory.base.util.excel;

import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.document.AbstractXlsxView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.Map;

public class ExcelView  {

	public static void buildExcelDocument(Map<String, Object> model, Workbook workbook, HttpServletRequest request,
										  HttpServletResponse response) throws Exception {
		
		String fileName = model.get("title") + ".xlsx";
		fileName = new String(fileName.getBytes("gb2312"), "iso8859-1");
		
		response.setContentType("application/vnd.ms-excel");
		response.setHeader("Content-disposition", "attachment;filename=" + fileName);
		
		OutputStream out = response.getOutputStream();
		workbook.write(out);
		out.flush();
		out.close();
	}
	

}
